package pl.edu.agh.persdoc.resultsws;
/**
 * Copyright 2005-2010 Noelios Technologies.
 * 
 * The contents of this file are subject to the terms of one of the following
 * open source licenses: LGPL 3.0 or LGPL 2.1 or CDDL 1.0 or EPL 1.0 (the
 * "Licenses"). You can select the license that you prefer but you may not use
 * this file except in compliance with one of these Licenses.
 * 
 * You can obtain a copy of the LGPL 3.0 license at
 * http://www.opensource.org/licenses/lgpl-3.0.html
 * 
 * You can obtain a copy of the LGPL 2.1 license at
 * http://www.opensource.org/licenses/lgpl-2.1.php
 * 
 * You can obtain a copy of the CDDL 1.0 license at
 * http://www.opensource.org/licenses/cddl1.php
 * 
 * You can obtain a copy of the EPL 1.0 license at
 * http://www.opensource.org/licenses/eclipse-1.0.php
 * 
 * See the Licenses for the specific language governing permissions and
 * limitations under the Licenses.
 * 
 * Alternatively, you can obtain a royalty free commercial license with less
 * limitations, transferable or non-transferable, directly at
 * http://www.noelios.com/products/restlet-engine
 * 
 * Restlet is a registered trademark of Noelios Technologies.
 */

import java.io.IOException;
import java.io.StringReader;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.restlet.data.ChallengeResponse;
import org.restlet.data.ChallengeScheme;
import org.restlet.data.Form;
import org.restlet.data.MediaType;
import org.restlet.ext.xml.DomRepresentation;
import org.restlet.ext.xml.XmlRepresentation;
import org.restlet.resource.ClientResource;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

import pl.edu.agh.mobilne.DomRepresentationResource;

public class ApplicationTest {
    public static final String APPLICATION_URI = "http://localhost:3000/resultsws";

  
    public static String getResultsUri(String meaurementID) {
        return APPLICATION_URI + "/results/" + meaurementID;
    }


    public static void main(String[] args) throws Exception {
  
    	putResult("notinterpretedID1");
    		
    }

    public static void putResult(String id) {

        //ClientResource resource = new ClientResource(getResultsUri(id));
        ClientResource cr = new ClientResource(getResultsUri(id));
        DomRepresentationResource resource = cr.wrap(DomRepresentationResource.class);
        DomRepresentation d=null;
        String xmlSource = "<Measurement><patientID>1</patientID><name>blood presure</name><value>"+ "12345" + "</value><timestamp>2010-11-16T09:33:12</timestamp></Measurement>";

        
        try {
        	DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
            DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
			Document doc = docBuilder.parse(new InputSource(new StringReader(xmlSource)));
			d = new DomRepresentation(MediaType.TEXT_XML, doc);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SAXException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ParserConfigurationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
        resource.store(xmlSource);   
        //System.out.println(resource.getStatus());
        
    }

    
}
